package Demo2;


class Shape {

    void draw(){
        System.out.println("画画");
    }
}
class Square extends Shape{

    @Override
    void draw(){
        System.out.println("画出一个正方形......");
    }
}
class Triangle extends Shape{

    @Override
    void draw() {
        System.out.println("画出一个三角形......");
    }
}
class Cycle extends Shape{

    @Override
    void draw() {
        System.out.println("画出一个圆.......");
    }
    public static void main(String[] args) {
        //创建对象，向上转型
        Shape shape1 = new Square();
        Shape shape2 = new Triangle();
        Shape shape3 = new Cycle();

        Shape[] shape = {shape3,shape2,shape1,shape2,shape3};
        //多态
        for (Shape tem : shape) {
        tem.draw();
    }
}


//    public static void main(String[] args) {
//        //创建对象，向上转型
//        Shape shape1 = new Square();
//        Shape shape2 = new Triangle();
//        Shape shape3 = new Cycle();
//
//        String[] shape = {"cycle","triangle","square","triangle","cycle"};
//
//        for (int i = 0; i < shape.length; i++) {
//
//            //创建一个临时变量接收
//            String shapeT = shape[i];
//            //判断
//            if (shapeT.equals("cycle")) {
//                shape3.draw();
//            } else if (shapeT.equals("triangle")) {
//                shape2.draw();
//            } else if (shapeT.equals("square")) {
//                shape1.draw();
//            }
//        }
//    }
}
